/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.database.tables;

import aiaudio.database.Family;
import aiaudio.database.qualifiers.LongQualifier;
import java.io.IOException;
import org.apache.hadoop.hbase.client.HTable;

/**
 *
 * @author nastya
 */
public class DataMetricsTable extends TableStructure {

    private static final Family VALUE = new Family("v");
    private static final Family PARAMS = new Family("p");
    private static final LongQualifier COUNT = new LongQualifier("cnt");

    @Override
    public Family[] getAllFamilies() {
        return new Family[]{VALUE, PARAMS};
    }

    private static void incrementValue(HTable table, String row, long value) throws IOException {
        TableStructure.incrementColumnValue(table, row, VALUE, COUNT, value);
    }

    public static void incrementArtistsCount(HTable table) throws IOException {
        TableStructure.incrementColumnValue(table, ConstantRows.ArtistsCount.getName(), VALUE, COUNT, 1L);
    }

    public static long getArtistsCount(HTable tableInstance) throws IOException {
        return getCount(tableInstance, ConstantRows.ArtistsCount.getNameAsBytes());
    }

    public static void incrementUsersCount(HTable table) throws IOException {
        TableStructure.incrementColumnValue(table, ConstantRows.UsersCount.getName(), VALUE, COUNT, 1L);
    }

    public static long getUsersCount(HTable tableInstance) throws IOException {
        return getCount(tableInstance, ConstantRows.UsersCount.getNameAsBytes());
    }

    public static void incrementRatingsCount(HTable table) throws IOException {
        TableStructure.incrementColumnValue(table, ConstantRows.RatingsCount.getName(), VALUE, COUNT, 1L);
    }

    public static long getRatingsCount(HTable tableInstance) throws IOException {
        return getCount(tableInstance, ConstantRows.RatingsCount.getNameAsBytes());
    }

    private static long getCount(HTable tableInstance, byte[] artistId) throws IOException {
        return TableStructure.getSingleColumnValue(tableInstance, artistId,
                VALUE, COUNT);
    }
}
